﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF
{
    class Program
    {
        static void Main(string[] args)
        {
            MyDbContext dd = new MyDbContext();
            #region 新增
            //Student ss = new Student()
            //{
            //    Name = "雷龙",
            //    Set = "女"
            //};
            //Console.WriteLine(dd.Entry(ss).State);//Detached
            //dd.Students.Add(ss);
            //Console.WriteLine(dd.Entry(ss).State);//Added
            //int num = dd.SaveChanges();
            //Console.WriteLine(dd.Entry(ss).State);//Unchanged
            //if (num > 0)
            //{
            //    Console.WriteLine("ok");
            //}
            #endregion
            #region 修改1
            //Student ss = new Student()
            //{
            //    Id = 1,
            //    Name = "王忠贵",
            //    Set = "男"
            //};
            //dd.Students.Attach(ss);
            //dd.Entry(ss).State = EntityState.Modified;
            //int num = dd.SaveChanges();
            //if (num > 0)
            //{
            //    Console.WriteLine("ok");
            //}
            #endregion
            #region 修改2
            //Student ss = dd.Students.Where(e => e.Id == 1).FirstOrDefault();
            //ss.Name = "雷龙";
            //int num = dd.SaveChanges();
            //if (num > 0)
            //{
            //    Console.WriteLine("ok");
            //}
            #endregion
            #region 删除1
            //Student ss1 = new Student() { Id = 2 };
            //dd.Students.Attach(ss1);
            //dd.Students.Remove(ss1);
            //int num1 = dd.SaveChanges();
            //if (num1 > 0)
            //{
            //    Console.WriteLine("ok");
            //}
            #endregion
            #region 删除2
            //Student ss2 = dd.Students.Where(e => e.Id == 5).FirstOrDefault();
            //dd.Students.Remove(ss2);
            //int num2 = dd.SaveChanges();
            //if (num2 > 0)
            //{
            //    Console.WriteLine("ok");
            //}
            #endregion
            Console.ReadLine();
        }
    }
}
